package threadpolls.simplepoll;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.Test;

/**
 * @author z
 */
public class Poll1 {

    @Test(invocationCount = 20)
    public void t1() {
        ExecutorService executor = new ThreadPoolExecutor(
            1,
            2,
            0,
            TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<>(1));
        // 线程数量大于2的时候就可能会执行拒绝策略
         for (int i = 0; i < 6; i++) {
             executor.execute(new Task());
         }


    }

}

class Task implements Runnable {

    @Override public void run() {
        System.out.println("execute");
    }
}
